<template>
    <div>
        <h1>login</h1>
        <el-input v-model="uname" placeholder="请输入用户名"></el-input>
        <el-input v-model="upwd" placeholder="请输入密码" show-password></el-input>
        <el-button @click="login" class="login">登录</el-button>
    </div>
</template>
<script>
export default {
  data() {
    return {
      uname: '',
      upwd:''      
    }
  },
  methods:{
      login(){
          var u=this.uname
          var p=this.upwd
          
          var reg=/^[a-z0-9]{3,12}$/i;
          if(!reg.test(u)){
              alert('用户名格式不正确')
              return
          }
          if(!reg.test(p)){
              alert('密码格式不正确')
              return
          }
          var url="login";
          var obj={uname:u,upwd:p};
          this.axios.get(url,{params:obj})
          .then(res=>{
             if(res.data.code == -1){
         alert("用户名或密码有误")
         }else{
         alert("登录成功");
      //10:跳转商品列表组件 /Product
         this.$router.push("./");
        }
          })
      }
  }
}
</script>
<style scoped>
  .login{
      display: block;
      margin: 2rem auto ;
  }
</style>

